//
//  TuanCell.m
//  MyTest
//
//  Created by zhiyou on 16-4-20.
//  Copyright (c) 2016年 wangyang. All rights reserved.
//

#import "TuanCell.h"

@implementation TuanCell
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _imgView = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self addSubview:_imgView];
        
        [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(10);
            make.centerX.equalTo(self.mas_centerX);
            make.width.height.equalTo(self.mas_width).multipliedBy(.7);
        }];
        
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = [UIFont systemFontOfSize:12];
        _titleLab.numberOfLines = 2;
        [self addSubview:_titleLab];
        
        [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_imgView.mas_bottom).offset(5);
            make.left.offset(10);
            make.right.offset(-10);
            make.height.equalTo(self.mas_height).multipliedBy(.2);
        }];
        
        _cheapLab = [[UILabel alloc] init];
        _cheapLab.font = [UIFont systemFontOfSize:10];
        _cheapLab.backgroundColor = [UIColor redColor];
        _cheapLab.layer.cornerRadius = 5;
        _cheapLab.textColor = [UIColor whiteColor];
        [self addSubview:_cheapLab];
        
        [_cheapLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(5);
            make.top.equalTo(_titleLab.mas_bottom).offset(0);
        }];

        _priceLab = [[UILabel alloc] init];
        _priceLab.textColor = [UIColor redColor];
        _priceLab.font = [UIFont systemFontOfSize:15];
        [self addSubview:_priceLab];
        
        [_priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleLab.mas_bottom).offset(0);
            make.right.offset(-10);
        }];
        
        
        _originalLab = [[UILabel alloc] init];
        _originalLab.font = [UIFont systemFontOfSize:10];
        [self addSubview:_originalLab];
        
        [_originalLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_priceLab.mas_left).offset(-5);
            make.top.equalTo(_titleLab.mas_bottom).offset(5);
        }];

       

        UIView *line = [[UIView alloc] init];
        line.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:line];
        
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(20);
            make.right.offset(-20);
            make.top.equalTo(_cheapLab.mas_bottom).offset(10);
            make.height.offset(1);
        }];
        
        _countLab = [[UILabel alloc] init];
        _countLab.font = [UIFont systemFontOfSize:12];
        [self addSubview:_countLab];
        
        [_countLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(-10);
            make.bottom.offset(-5);
        }];
    }
    return self;
}

- (void)setTuanGou:(TuanGou *)tuanGou
{
    _tuanGou = tuanGou;
    
    [_imgView sd_setImageWithURL:[NSURL URLWithString:_tuanGou.img_path]];
    _titleLab.text = _tuanGou.title;
    _cheapLab.text = [NSString stringWithFormat:@"%@折",_tuanGou.discount];
    _originalLab.text = [NSString stringWithFormat:@"¥%@",_tuanGou.original_price];
    _priceLab.text = [NSString stringWithFormat:@"¥%@",_tuanGou.price];
    _countLab.text = [NSString stringWithFormat:@"已参团人数%@",_tuanGou.attend_count];
    
}

@end
